import axios from 'axios'
//添加请求拦截器
axios.interceptors.request.use((request) => {
  if(request.url.indexOf('crm_center')) {
    request.headers["token"] = '0a0258a8d1b84525fa5726a0090ded6cd29e029a51fa4f19b0a6c1c995e387bb';
  }
  if (typeof request.data != "object") {
    return request;
  }
  //request.headers["Content-Type"] = "application/json;charset=UTF-8";
  return request;
})

//添加响应拦截器，响应拦截器会在then/catch处理之前执行
axios.interceptors.response.use((response) => {
  if (response.data.code == '2015') {
    window.location.href = '/';
  }
  return response.data;
}, function (error) {
  return Promise.reject({
    code: "-999",
    msg: `[${error.response.status}]网络请求失败，请重试`,
    data: {
      status: error.response.status,
      statusText: error.response.statusText,
      error
    }
  });
});
